
#include "GLDebugDrawer.h"

#include <stdio.h> //printf debugging
//
//

GLDebugDrawer::GLDebugDrawer()
:m_debugMode(0)
{
	
}

void    GLDebugDrawer::drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
{
	//      if (m_debugMode > 0)
	{
		float tmp[ 6 ] = { from.getX(), from.getY(), from.getZ(),
			to.getX(), to.getY(), to.getZ() };
		
		glPushMatrix();
		{         
			glColor4f(color.getX(), color.getY(), color.getZ(), 1.0f);         
			glVertexPointer( 3,
							GL_FLOAT,
							0,
							&tmp );
			
			glPointSize( 5.0f );
			glDrawArrays( GL_POINTS, 0, 2 );
			glDrawArrays( GL_LINES, 0, 2 );
		}
		glPopMatrix();      
	}
}

void    GLDebugDrawer::setDebugMode(int debugMode)
{
	m_debugMode = debugMode;
}

void    GLDebugDrawer::draw3dText(const btVector3& location,const char* textString)
{
	//glRasterPos3f(location.x(),  location.y(),  location.z());
	//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),textString);
}

void    GLDebugDrawer::reportErrorWarning(const char* warningString)
{
	printf("%s",warningString);
}

void    GLDebugDrawer::drawContactPoint(const btVector3& pointOnB,const btVector3& normalOnB,btScalar distance,int lifeTime,const btVector3& color)
{
	{
		btVector3 to=pointOnB+normalOnB*distance;
		const btVector3&from = pointOnB;
		glColor4f(color.getX(), color.getY(), color.getZ(), 1.0f);   
		
		//GLDebugDrawer::drawLine(from, to, color);
		
		vec3 v;
		
		v.x = from.x();
		v.y = from.y();
		v.z = from.z();
		
		//_debug_point( &v );
		
		//glRasterPos3f(from.x(),  from.y(),  from.z());
		//char buf[12];
		//sprintf(buf," %d",lifeTime);
		//BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
	}
}

void _debug_point( vec3 *_pt )
{
	float tmp[ 3]  = { _pt->x,
		_pt->y,
		_pt->z };
	
	vec4 col = { 1.0f,
		0.0f,
		0.0f,
		1.0f };	
	sio2MaterialReset();
	sio2ObjectReset();
	sio2StateSetColor(sio2->_SIO2state, &col );
	
	glPointSize( 10.0f );	
	glVertexPointer( 3, GL_FLOAT, 0, tmp );	
	glDrawArrays( GL_POINTS , 0, 1 );
}


void _debug_line( vec3 *_pt0,
				 vec3 *_pt1 )
{
	float tmp[ 6 ] = { _pt0->x, _pt0->y, _pt0->z,
		_pt1->x, _pt1->y, _pt1->z };
	
	vec4 col = { 1.0f,
		0.0f,
		0.0f,
		1.0f };
	
	sio2MaterialReset();
	sio2ObjectReset();
	sio2StateSetColor(sio2->_SIO2state, &col );
	glVertexPointer( 3, GL_FLOAT, 0, tmp );
	glDrawArrays( GL_LINES, 0, 2 );
}